package com.ycr.springmvc.bean;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import com.ycr.springmvc.event.AnimalSpeakEvent;

public class Animal implements ApplicationContextAware {

	private ApplicationContext ac;

	private String name;

	private int age;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public String speak() {
		ac.publishEvent(new AnimalSpeakEvent(this, this.name));
		return " 我的名字是;" + this.name + ",我的年龄是:" + this.age;
	}

	@Override
	public void setApplicationContext(ApplicationContext arg0)
			throws BeansException {
		this.ac = arg0;
	}

}
